﻿using project.B12.application.Extensions;
using project.B12.IService;
using project.B12.Model.Models;
using software.Common.MVVM;
using System;

namespace project.B12.application.ViewModels.Setting
{
    public class LogViewModel : ObservableObject
    {
        public ILogService LogService { get; set; }
        public IWorkSequence WorkSequence { get; set; }
        public DateTime StartData { get; set; }
        public DateTime EndData { get; set; }
        public string Type { get; set; }
        public string DetailInfo { get; set; }

        public TableLog? SelectedLog { get; set; }

        public LogViewModel(ILogService logService,IWorkSequence workSequence)
        {
            LogService = logService;
            WorkSequence = workSequence;
            StartData = DateTime.Now;
            EndData = DateTime.Now;
        }

        public RelayCommand ShowCommand => new RelayCommand(Show);
        public RelayCommand SearchCommand => new RelayCommand(Search);
        public RelayCommand ShowDetailedCommand => new RelayCommand(ShowDetailed, () => SelectedLog != null);


        private async void ShowDetailed()
        {
            if (SelectedLog == null)
                return;
            string content =
                $"类型：{SelectedLog.Type}, " +
                $"用户：{SelectedLog.User}, " +
                $"时间：{SelectedLog.DateTime}, " +
                $"设备号：{SelectedLog.InstrumentId}, " +
                $"模块名：{SelectedLog.ModuleName}\r\n" +
                $"详细内容：\r\n{SelectedLog.Text}";
            await DialogExtensions.MessageTip("日志", content);
        }

        private void Search()
        {
            LogService.Search(StartData, EndData, Type, DetailInfo);
        }

        private void Show()
        {
            LogService.Show();
        }
    }
}
